package cc.linker.steplink.crm.merchant.controller;

import cc.linker.steplink.crm.commons.model.PcUserInfo;
import cc.linker.steplink.crm.merchanth5.commons.UserInfoUtil;
import cc.linker.steplink.crm.merchant.pojo.MessageTipPo;
import cc.linker.steplink.crm.merchant.service.MessageTipService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @Description: 消息通知
 * @Author: ch
 * @Date: 2020/7/2 20:07
 * @Version: 1.12.6
 **/
@RestController
@RequestMapping("/messageTip")
public class MessageTipController {

    @Autowired
    private MessageTipService messageTipService;
    @Autowired
    private UserInfoUtil userInfoUtil;


    /**
     * @Description: 列表
     * @Param: [pageIndex, pageSize]
     * @Return: com.github.pagehelper.PageInfo
     * @Author: ch
     * @Date: 2020/7/2 20:07
     * @Version: 1.12.6
     **/
    @GetMapping("/list")
    public PageInfo list(
            @RequestParam(value = "pageIndex", defaultValue = "1", required = false) Integer pageIndex,
            @RequestParam(value = "pageSize", defaultValue = "10", required = false) Integer pageSize
    ){
        PageHelper.startPage(pageIndex, pageSize);
        return new PageInfo<>(messageTipService.list());
    }

    /**
     * 详情
     * @param : id   主键id
     * @Author: ch
     * @Date: 2020/7/2 20:07
     * @Version: 1.12.6
     */
    @GetMapping("/info")
    public MessageTipPo infoById(Long id) {
        return messageTipService.infoById(id);
    }

    /**
     * 阅读消息
     * @param : id   主键id
     * @Author: ch
     * @Date: 2020/7/2 20:07
     * @Version: 1.12.6
     */
    @PostMapping("/read")
    public void read(@RequestBody Map<String,Object> params, HttpServletRequest request){
        PcUserInfo userinfo = this.userInfoUtil.getPcUserInfo(request);
        params.put("userId",userinfo.getAdminId());
        messageTipService.read(params);
    }

    /**
     * 概况消息列表
     * @param : id   主键id
     * @Author: ch
     * @Date: 2020/7/2 20:07
     * @Version: 1.12.6
     */
    @GetMapping("/viewList")
    public List<MessageTipPo> viewList(HttpServletRequest request){
        PcUserInfo userinfo = this.userInfoUtil.getPcUserInfo(request);
        return messageTipService.viewList(userinfo.getPayMode(),userinfo.getAdminId());
    }


    /**
     * @Description: 保存
     * @param : id  主键id（新增不传）
     * @param : name  名称
     * @param : instruction  说明
     * @param : content  内容
     * @param : type  类型，1文本2海报
     * @param : payMode  通知版本，1微信2联汇3云听荟通联
     * @param : startTime  开始时间
     * @param : endTime  结束时间
     * @Return: void
     * @Author: ch
     * @Date: 2020/7/2 19:44
     * @Version: 1.12.6
     **/
    @PostMapping("/save")
    public void save(@RequestBody Map<String,Object> params) {
        messageTipService.save(params);
    }

    /**
     * @Description: 修改状态
     * @param : id  主键id
     * @param : status  状态
     * @Return: void
     * @Author: ch
     * @Date: 2020/7/2 20:11
     * @Version:
     **/
    @PostMapping("/updateStatus")
    public void updateStatus(@RequestBody Map<String,Object> params) {
        messageTipService.updateStatus(params);
    }

    /**
     * @Description: 删除
     * @param : id  主键id
     * @Return: void
     * @Author: ch
     * @Date: 2020/7/2 20:11
     * @Version:
     **/
    @PostMapping("/delete")
    public void delete(@RequestBody Map<String,Object> params) {
        messageTipService.delete(params);
    }

}
